package com.anycl.design.j2ee.interceptingfilter;


import java.util.LinkedList;
import java.util.List;

public class FilterChain {
    // 过滤器集合
    private List<Filter> filters = new LinkedList<>();
    // 过滤的目标对象
    private Target target;

    public void addFilter(Filter filter) {
        filters.add(filter);
    }

    public void setTarget(Target target) {
        this.target = target;
    }

    public void doFilter(String request) {
        // 先调用过滤器集合，执行一系列的过滤拦截
        filters.stream().forEach(filter -> filter.doFilter(request));
        // 执行目标对象自己的业务逻辑
        target.execute(request);
    }
}
